package com.xiang.activity;

import com.xiang.seemovies.R;

import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import cn.edu.fzxy.zxy.niceday.examples.BaseActivity;

public class DealHTML5Activity extends BaseActivity {
	private WebView mywebview;
	private String url;
	private ImageView back;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.html5_page_layout);

		mywebview = (WebView) findViewById(R.id.htm5_webview);
		mywebview.getSettings().setJavaScriptEnabled(true);
		String urlStr = "http://dpurl.cn/p/duGYLgdoEg";
		mywebview.loadUrl(urlStr);
		mywebview.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}
		});

		mywebview.setWebViewClient(new WebViewClient() {
			ProgressDialog progressDialog;

			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				super.onPageStarted(view, url, favicon);
				System.out.println("########webview开始加载");
				if (progressDialog ==null) {
					progressDialog = ProgressDialog.show(
							DealHTML5Activity.this, null, "正在加载……");
				}

			}

			@Override
			public void onPageFinished(WebView view, String url) {
				super.onPageFinished(view, url);
				System.out.println("########webview加载结束");
				progressDialog.dismiss();
			}
		});

		back = (ImageView) findViewById(R.id.html5_page_back);
		back.setOnClickListener(new ImageView.OnClickListener() {
			@Override
			public void onClick(View v) {
				DealHTML5Activity.this.finish();
				overridePendingTransition(R.anim.left_in, R.anim.right_out);
			}
		});

	}

	private void initData() {
		url = getIntent().getStringExtra("url");
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			DealHTML5Activity.this.finish();
			overridePendingTransition(R.anim.left_in, R.anim.right_out);
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
}
